<{Tinclude "commom/admin_header"}>
<style>
     .jpinput{
         width: 40px;
         height: 20px;
     }
     .inputwater_price{
         display: none;
     }
     .inputdian_price{
         display: none;
     }
 </style>
 <section id="container" >


      <!--顶部-->
      <{Tinclude"commom/admin_inner_header"}>
      <!--顶部-->
      
       <{Tinclude"commom/admin_left_menu"}>
       
       <section id="main-content">
          <section class="wrapper">
          	<h3><i class="<{if $___menuinfo["iconclass"]}><{$___menuinfo["iconclass"]}><{else}>fa fa-list-ul<{/if}>"></i><{$___menuinfo["base_name"]}></h3>
                <div class="row mt">
                    <div class="col-md-12">
                       <div class="form-panel">  
                           
                           
                           <div class='col-md-2'>
                               
                               
                           </div>
                           <div class="col-md-10 text-right">
                                   
                                 <form class="form-inline" method="post" action="<{echo Common::RewriteUrl($jp_arg["c"],$jp_arg["a"]);}>">
                                       <div class="form-group">
        <select name="year" id="exampleInputName2" class="form-control">
           <option value="">2015</option>
                <option value="">2016</option>
        
        </select>
  
    <label for="exampleInputName2">年</label>
  </div>
           
   <div class="form-group">
         <select name="month" class="form-control" id="exampleInputName3">
                <option value="">1</option>
                <option value="">2</option>
         </select>
       
       <label for="exampleInputName3">月份</label>
   </div>
  <div class="form-group">
    <label for="exampleInputName2">租户姓名</label>
    <input type="text" name="seach_user_name" value="<?php if(isset($jp_arg['seach_user_name']))echo $jp_arg['seach_user_name'];?>" class="form-control" id="exampleInputName2" placeholder="租户姓名">
  </div>
   <div class="form-group">
    <label for="exampleInputName3">房间编号</label>
    <input type="text" name="seach_room_no" value="<?php if(isset($jp_arg['seach_room_no']))echo $jp_arg['seach_room_no'];?>" class="form-control" id="exampleInputName3" placeholder="房间编号">
  </div>
  <button type="submit" class="btn btn-default">搜索</button>
</form>
                                   
                                   
                               </div>
                           <div class='clearfix'></div>
                           <div class='margin_top20'></div>
                           <div class="col-lg-12">
                           <div class="row">
                               
         <{if $list}>                            
  <section id="no-more-tables">                   
  <table class="table table-striped table-condensed table-hover cf">
      <thead class="cf">
        <tr>
            <th class="text-center">租户</th>
          <th class="text-center">房间</th>
          <th class="text-center">水费</th> 
          <th class="text-center">电费</th> 
          <th class="text-center">应缴金额</th> 
          <th class="text-center"><span class="fa fa-info-circle"></span>已经缴纳</th>
          <th class="text-center">时间</th>
          <th class="text-center">状态</th>
          <th class="text-center">操作</th>
        </tr>
      </thead>
      <tbody>
   
          <{foreach $list as $item}>
          <tr>
              <td data-title="租户" class="text-center"><a href="<{echo Common::RewriteUrl("Rental","tuifang","&id=".$item["rid"]);}>" ><{$item["user_name"]}></a></td>
              <td data-title="房间" class="text-center"><{$item["local"]}>-<{$item["layer_id"]}>楼-<{$item["room_no"]}></td>
              <td data-title="水费" class="text-center editwater_price" data-rid="<{$item["id"]}>"><span class="txtwater_price"><{$item["l_water_price"]}></span><span class="inputwater_price"><input class="form-control jpinput" name="jpshuidun" /></span></td>
              <td data-title="电费" class="text-center editdian_price" data-rid="<{$item["id"]}>"><span class="txtdian_price"><{$item["l_dian_price"]}></span><span class="inputdian_price"><input class="form-control jpinput" name="jpsdiandu" /></span></td>
              <td data-title="租金" class="text-center"><{echo $item["l_total"]-$item["r_total"];}></td>
              <td data-title="已经缴纳" class="text-center"><div data-toggle="tooltip" data-placement="top" title="<{$item["r_total"]}>=(租金)<{$item["r_rent"]}>+(电费)<{$item["r_dian_price"]}>+(水费)<{$item["r_water_price"]}>"><{$item["r_total"]}></div></td>
              <td data-title="时间" class="text-center"><{echo $item["year"]."年".$item["month"]."月"}></td>
              <td  data-title="状态" class="text-center"><{if $item["is_payfinsh"]==0}><b style="color:red;">[房租待交]</b><{else}><b>[房租已交]</b><{/if}></td>
              <td data-title="操作" class="text-center">
                  <div class="btn-group">  
                       <{if $item["zustatus"]!=0}> <a  data-toggle="modal" data-target="#rentedit" title="交租" class="btn btn-primary btn-xs" data-rid="<{$item["id"]}>" ><span class="fa fa-cny"></span>交租</a>
                      <{if $item["rentitemcount"]>0}><a href="<{echo Common::RewriteUrl("Rental","confirmjiaozu","&rentid=".$item["id"]);}>" title="待确定租金" class="btn btn-success btn-xs" data-rid="<{$item["id"]}>" ><span class="fa fa-question-circle"></span>待确定租金(<{$item["rentitemcount"]}>)</a><{/if}>
                      <{else}>已搬走<{/if}>
                      
              </div>
              </td>
          </tr>
          <{/foreach}>
       
      </tbody>
  </table>
</section>
                              
                          <div class="col-md-12 text-center">
                           <?php Temp::Tinclude("commom/pager");?>
                          </div>
                      <{else}>
                        <div class="col-md-12 col-xs-12">
                                 <h4 class="text-center">数据为空</h4>
                             </div>
                       <{/if}>           
                               
                           </div>
                           </div>
                           <div class="clearfix"></div>
                           
                           
 
                           
                           
                           
                       </div>
                    </div>
                </div>
          </section>
       </section>
 </section>
 
 
 
 <!--交房租-->
<div class="modal fade" id="rentedit" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">缴纳房租</h4>
      </div>
        <div class="modal-body">
            
            <form id="myform">
                <input type="hidden" class="form-control" name="rentid">
                  <div class="form-group input-group col-md-12">
                    <span class="input-group-addon">房间编号</span>
                    <input type="text" class="form-control" readonly="readonly"  name="room_no" placeholder="房间编号">
                 </div>
                <div class="form-group input-group col-md-12">
                    <span class="input-group-addon">租户</span>
                    <input type="text"  class="form-control" readonly="readonly"  name="user_name" placeholder="租户">
                </div>
                <div class="form-group  col-md-6 ">
                    
                </div>
                <div class="form-group  col-md-6">
                    
                </div>
                
                
                <div class="form-group input-group col-md-12">
         <span class="input-group-addon">实收租金</span>
          <input type="text" class="form-control" name="rent" placeholder="请输入租金">        
          <span class="input-group-addon">(元/月)</span>
      </div>
           
     <div class="form-group input-group col-md-12">
         <span class="input-group-addon">实收水费</span>
          <input type="text" class="form-control" name="water_price" value="0" placeholder="请输入水费">        
          <span class="input-group-addon">(元)</span>
      </div>
           
     <div class="form-group input-group col-md-12">
         <span class="input-group-addon">实收电费</span>
         <input type="text" class="form-control" name="dian_price" value="0" placeholder="请输入电费">        
          <span class="input-group-addon">(元)</span>
      </div>
            </form>
            
        </div>
         <div class="modal-footer">
        <button type="button" class="btn btn-success" id="btnrentedit">提交</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>
<script>
    $(document).ready(function(){
        initdate();
        $(".jppdelete").click(function(){
            var href=$(this).data("href");
            if(window.confirm("确定要退房吗?")){
                window.location.href=href;
            }
        });
    });
    $(function () {
  $('[data-toggle="tooltip"]').tooltip();
});

	$(".editwater_price").click(function(){
         var span=$(this).children(".txtwater_price");  
         var id=$(this).data("rid");
         var spaninput=$(this).children(".inputwater_price");  
         var input=spaninput.children(".jpinput");
           if(span.css("display")!="none"){
                span.css("display","none");
                spaninput.css("display","inline-block");
                input.css("padding","6px 0px");
                input.css("font-size","12px");
                input.val(span.html());
                
                
              
                $.post("<{echo Common::RewriteUrl("Rental","public_ajax_rent");}>",{"id":id},function(data){
                    $("#btnjisuanshuifei").data("inputname","jpshuidun");
                    $("#jisuanshuifei").modal('show');
        if(data.status==1){
        $("input[name='dunshu']").val(data.msg.shui_du);    
        $("input[name='predunshu']").val(data.msg.preshui_du);
        }else{
            alert(data.msg);
        }
    },"json");
                
                input.blur(function(){
                    
                    var dunshu=$("input[name='dunshu']").val();
                    updatedianwater("water",input.val(),dunshu,id,span,spaninput,input);
                   
                });
                
            }
        });
        
        
        $(".editdian_price").click(function(){
         var span=$(this).children(".txtdian_price");  
          var id=$(this).data("rid");

         var spaninput=$(this).children(".inputdian_price");  
         var input=spaninput.children(".jpinput");
           if(span.css("display")!="none"){
                span.css("display","none");
                spaninput.css("display","inline-block");
                input.css("padding","6px 0px");
                input.css("font-size","12px");
                input.val(span.html());
                
                     $.post("<{echo Common::RewriteUrl("Rental","public_ajax_rent");}>",{"id":id},function(data){
                    $("#btnjisuandianfei").data("inputname","jpsdiandu");
                    $("#jisuandianfei").modal('show');
        if(data.status==1){
            $("input[name='dushu']").val(data.msg.dian_du);     
        $("input[name='predushu']").val(data.msg.predian_du);
        }else{
            alert(data.msg);
        }
    },"json");
                
                input.blur(function(){
                    var dushu=$("input[name='dushu']").val();
                    updatedianwater("dian",input.val(),dushu,id,span,spaninput,input);
                    
                });
            }
        });
        function updatedianwater(type,val,liang,id,span,spaninput,input){
            $.post("<{echo Common::RewriteUrl("Rental","public_ajax_updatedianwater");}>",{"type":type,"vl":val,"liang":liang,"id":id},function(data){
                if(data.status==1){
                    span.html(input.val());
                    
                    span.css("display","inline-block");
                    spaninput.css("display","none");
                    //alert("更新成功");
                    window.location.reload();
                }else{
                    alert(data.msg);
                    window.location.reload();
                }
            },"json");
        }
        
        
        $('#rentedit').on('show.bs.modal', function (event){
    var button = $(event.relatedTarget);
    
    var id=button.data("rid");
    $("input[name='rentid']").val(id);
    $.post("<{echo Common::RewriteUrl("Rental","public_ajax_rent");}>",{"id":id},function(data){
        if(data.status==1){
             $("input[name='room_no']").val(data.msg.room_no);
             $("input[name='user_name']").val(data.msg.user_name);
             if((parseFloat(data.msg.l_rent)+parseFloat(data.msg.l_water_price)+parseFloat(data.msg.l_dian_price))==parseFloat(data.msg.l_total)){
                  $("input[name='rent']").val(parseFloat(data.msg.l_rent)-parseFloat(data.msg.r_rent));
                  $("input[name='water_price']").val(parseFloat(data.msg.l_water_price)-parseFloat(data.msg.r_water_price));
                  $("input[name='dian_price']").val(parseFloat(data.msg.l_dian_price)-parseFloat(data.msg.r_dian_price));
             }else{
                 var dit=parseFloat(data.msg.l_total)-parseFloat(data.msg.r_total);
                 var tv1=dit/3;
                 var tv2=dit/3;
                 var tv3=dit-tv1.toFixed(2)-tv2.toFixed(2);
                 $("input[name='rent']").val(tv3.toFixed(2));
                  $("input[name='water_price']").val(tv1.toFixed(2));
                  $("input[name='dian_price']").val(tv2.toFixed(2));
             }
        }else{
            alert(data.msg);
        }
    },"json");
});
$("#btnrentedit").click(function(){
    $.ajax({
        type:"POST",
        url:"<{echo Common::RewriteUrl("Rental","public_ajax_jiaozu2");}>",
        data:$("#myform").serialize(),
        async:false,
        dataType:"json",
        success:function(data){
        
            if(data.status==1){
                alert("缴纳成功!");
                $('#rentedit').modal('hide');
                window.location.reload();
            }else{
                alert(data.msg);
            }
          
        }
    });


});
  function initdate(){
        var _now=new Date();
        var year=<{if isset($jp_arg["year"])}><{$jp_arg["year"]}><{else}>_now.getFullYear()<{/if}>;
        var month=<{if isset($jp_arg["month"])}><{$jp_arg["month"]}><{else}>_now.getMonth()+1<{/if}>;
        var curyear=<{if isset($jp_arg["year"])}><{$jp_arg["year"]}><{else}>""<{/if}>;
        var curmonth=<{if isset($jp_arg["month"])}><{$jp_arg["month"]}><{else}>""<{/if}>;
        var selectyear=$("select[name='year']");
        var selectmonth=$("select[name='month']");
        selectyear.empty();
        selectmonth.empty();
        var option1 = $("<option>").val("").text("不限");
        selectyear.append(option1.clone());
        selectmonth.append(option1);  
        for(var i=year-4;i<year+4;i++){
            if(i==curyear){
                var option = $("<option>").val(i).text(i);
                option.attr("selected",true);
            }else{
                var option = $("<option>").val(i).text(i);
            }
            selectyear.append(option);
        }
        for(var j=1;j<=12;j++){
          if(j==curmonth){
                var option = $("<option>").val(j).text(j);
                option.attr("selected",true);
            }else{
                var option = $("<option>").val(j).text(j);
            }
            selectmonth.append(option);  
        }
    }      
        
</script>
<{Tinclude"commom/jisuandianfei_form"}>
<{Tinclude"commom/jisuanshuifei_form"}>
<{Tinclude"commom/admin_footer"}>